using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    class MRPMenusService 
    {
        ISession session;

        public MRPMenusService( )
        {
            this.session = SessionFactory.GetNewSession();
        }

        public void InsertMrpmenus(MRPMenus mrpmenusX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpmenusX);
            tx.Commit();
        }

        public void UpdateMrpmenus(MRPMenus mrpmenusX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpmenusX);
            tx.Commit();
        }

        public void DeleteMrpmenus(MRPMenus mrpmenusX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpmenusX);
            tx.Commit();
        }

        public IList<MRPMenus> GetAllMrpmenus(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPMenus");
            IList<MRPMenus> list = query.List<MRPMenus>();
            if (evict)
            {
                foreach (MRPMenus s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPMenus GetAllMrpmenusByID(String id,Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPMenus as c where c.Menuid= :x");
            query.SetString("x", id);
            MRPMenus s = (MRPMenus)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPMenus> GetMrpmenusByQuery(IQuery query,Boolean evict)
        {
            IList<MRPMenus> list = query.List<MRPMenus>();
            if (evict)
            {
                foreach (MRPMenus s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
